export const dateToString = (d, Min) => {
  const date = new Date();
  const min = date.getMinutes();
  date.setMinutes(min + Min);
  const year = date.getFullYear();
  const month = (date.getMonth() + 1) < 10 ? ("0" + (date.getMonth() + 1)) : (date.getMonth() + 1);
  const day = date.getDate() < 10 ? ("0" + date.getDate()) : date.getDate();
  const hours = date.getHours() < 10 ? ('0' + date.getHours()) : date.getHours()
  const minutes = date.getMinutes() < 10 ? ('0' + date.getMinutes()) : date.getMinutes()
  const seconds = date.getSeconds() < 10 ? ('0' + date.getSeconds()) : date.getSeconds()
  const formatDate = year + '-' + month + '-' + day + " " + hours + ":" + minutes + ":" + seconds;
  return formatDate;
}
export const dateToString2 = (d, Min) => {
  const date = new Date();
  const min = date.getSeconds();
  date.setSeconds(min + Min);
  const year = date.getFullYear();
  const month = (date.getMonth() + 1) < 10 ? ("0" + (date.getMonth() + 1)) : (date.getMonth() + 1);
  const day = date.getDate() < 10 ? ("0" + date.getDate()) : date.getDate();
  const hours = date.getHours() < 10 ? ('0' + date.getHours()) : date.getHours()
  const minutes = date.getMinutes() < 10 ? ('0' + date.getMinutes()) : date.getMinutes()
  const seconds = date.getSeconds() < 10 ? ('0' + date.getSeconds()) : date.getSeconds()
  const formatDate = year + '-' + month + '-' + day + " " + hours + ":" + minutes + ":" + seconds;
  return formatDate;
}
export const dateMinutes = (time) => {
  var date2 = new Date();    // 结束时间

  var ms = Math.round(Math.abs(date2 - new Date(time)) / 1000);
  return ms;
}
export const nowTime = (time) => {
  var myDate = new Date();
  var year = myDate.getFullYear(); // 获取当前年
  var mon = myDate.getMonth() + 1 < 10 ? "0" + (myDate.getMonth() + 1) : myDate.getMonth() + 1; // 获取当前月
  var date = myDate.getDate() < 10 ? "0" + myDate.getDate() : myDate.getDate(); // 获取当前日
  var hour = myDate.getHours() < 10 ? "0" + myDate.getHours() : myDate.getHours();// 获取当前时
  var minute = myDate.getMinutes() < 10 ? "0" + myDate.getMinutes() : myDate.getMinutes();// 获取当前分
  var seconds = myDate.getSeconds() < 10 ? "0" + myDate.getSeconds() : myDate.getSeconds();// 获取当前分
  return year + "-" + mon + "-" + date + " " + hour + ":" + minute + ":" + seconds;
}
export const getTime = (time) => {
  var hours = Math.floor(time / 3600);
  var minutes = Math.floor((time - (hours * 3600)) / 60);
  var seconds = time - (hours * 3600) - (minutes * 60);
  seconds = Math.round(seconds * 100) / 100
  var result = (hours < 10 ? "0" + hours : hours);
  result += ":" + (minutes < 10 ? "0" + minutes : minutes);
  result += ":" + (seconds  < 10 ? "0" + seconds : seconds);
  return result;
}
export const processDate = (time, time2, type) => {
  var nowTime = new Date();
  var nowYear = nowTime.getFullYear();
  var nowday = nowTime.getDate() < 10 ? "0" + nowTime.getDate() : nowTime.getDate(); // 获取当前日

  var times = new Date(time);
  var year = times.getFullYear();
  var mon = times.getMonth() + 1 < 10 ? "0" + (times.getMonth() + 1) : times.getMonth() + 1; // 获取当前月
  var day = times.getDate() < 10 ? "0" + times.getDate() : times.getDate(); // 获取当前日
  var hour = times.getHours() < 10 ? "0" + times.getHours() : times.getHours();// 获取当前时
  var minute = times.getMinutes() < 10 ? "0" + times.getMinutes() : times.getMinutes();// 获取当前分
  var seconds = times.getSeconds() < 10 ? "0" + times.getSeconds() : times.getSeconds();// 获取当前分

  var times2 = new Date(time2);
  var year2 = times2.getFullYear();
  // var mon2 = times2.getMonth() + 1 < 10 ? "0" + (times2.getMonth() + 1) : times2.getMonth() + 1; // 获取当前月
  // var day2 = times2.getDate() < 10 ? "0" + times2.getDate() : times2.getDate(); // 获取当前日
  // var hour2 = times2.getHours() < 10 ? "0" + times2.getHours() : times2.getHours();// 获取当前时
  // var minute2 = times2.getMinutes() < 10 ? "0" + times2.getMinutes() : times2.getMinutes();// 获取当前分
  // var seconds2 = times2.getSeconds() < 10 ? "0" + times2.getSeconds() : times2.getSeconds();// 获取当前分

  if (year2 === year) {
    if (nowday === day) {
      if (type) {
        return hour + ':' + minute + ':' + seconds
      }
      return mon + '-' + day + '  ' + hour + ':' + minute + ':' + seconds
    }
    if (nowYear === year) {
      return mon + '-' + day + '  ' + hour + ':' + minute + ':' + seconds
    }
    return year + '-' + mon + '-' + day + '  ' + hour + ':' + minute + ':' + seconds
  } else {
    return time
  }
}

